﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Collections;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Input;

namespace vengeful_bean
{
    /*DEFINITIONS*/
    


    /*ENUMS*/
    public enum LEVEL
    { 
        ONE = 1, TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT, NINE, TEN, ELLEVEN 
    };
    
    public enum GAMESTATE
    {
        INTRO, PLAYING, PAUSED, DEAD, OUTRO, FINISHED
    };

    /*STRUCTS*/

    

    /*CLASSES*/

    public class IntroMovie
    {

        public string mssg = "VENGEFUL BEAN";
        public Vector2 position = new Vector2();

        public IntroMovie()
        {

        }

        public void Update(GameTime gameTime)
        {

        }

        public void Draw(SpriteBatch spriteBatch, SpriteFont font, GameTime gameTime)
        {

            spriteBatch.DrawString(font, this.mssg, this.position, Color.Black);
        }

    }

    public class Item
    {
        private string itemName;
        private Vector2 position;
        private bool active;

        public Item(string name, Vector2 pos)
        {
            this.itemName = name;
            this.position = pos;
            active = false;
        }

        public void Draw(SpriteBatch spriteBatch, SpriteFont font, GameTime gameTime)
        {
            if (active)
            {
                spriteBatch.DrawString(font, itemName, position, Color.Red);


            }
            else
            {
                spriteBatch.DrawString(font, itemName, position, Color.Black);

            }
        }

        public void SwitchSides()
        {
            active = !active;
        }

        public bool ShowStatus()
        {
            return active;
        }

        public override string ToString()
        {
            return itemName;
        }

    }

    public class IntroMenu
    {

        List<Item> items = new List<Item>(4);
        int active = 0;
        long timeLapsed = 0;
        public bool accepted = false;
        public string type;
        public LEVEL level;

        public IntroMenu()
        {
            items.Add(new Item(@"Level 1", new Vector2(200, 200)));
            items.Add(new Item(@"Level 2", new Vector2(200, 220)));
            items.Add(new Item(@"Level 3", new Vector2(200, 240)));
            items.Add(new Item(@"Exit", new Vector2(200, 260)));

            items[active].SwitchSides();

        }

        public void Update(GameTime gameTime)
        {
            KeyboardState keyState = Keyboard.GetState();
            timeLapsed += gameTime.ElapsedGameTime.Milliseconds;
            if (timeLapsed >= 130)
            {
                if (keyState.IsKeyDown(Keys.W) || keyState.IsKeyDown(Keys.Up))
                {
                    GoUp();
                }

                if (keyState.IsKeyDown(Keys.S) || keyState.IsKeyDown(Keys.Down))
                {
                    GoDown();
                }

                if (keyState.IsKeyDown(Keys.Enter) || keyState.IsKeyDown(Keys.Space))
                {

                    accepted = true;
                    type = items[active].ToString();
                    level = (LEVEL)(active + 1);
                    Debug.WriteLine("I have accepted: " + items[active].ToString());

                }

                timeLapsed = 0;
            }
        }

        private void GoDown()
        {
            items[active].SwitchSides();
            active++;
            if (active > items.Count - 1)
                active = 0;
            items[active].SwitchSides();

        }

        private void GoUp()
        {
            items[active].SwitchSides();
            active--;
            if (active < 0)
                active = items.Count - 1;
            items[active].SwitchSides();
        }

        public void Draw(SpriteBatch spriteBatch, SpriteFont font, GameTime gameTime)
        {
            for (int i = 0; i < items.Count; i++)
                items[i].Draw(spriteBatch, font, gameTime);

        }


    }

}
